package ar.edu.sccs.model.cbr;

import org.apache.log4j.Logger;

import ar.edu.sccs.dao.DaoModule;
import ar.edu.sccs.entities.Case;
import ar.edu.sccs.entities.Dimension;
import ar.edu.sccs.monitoring.logging.SCCSLogger;
import ar.edu.sccs.util.StringHelper;

public class FeedbackModule {

	static Logger logger = SCCSLogger.getLogger(FeedbackModule.class);

	private DaoModule daoModule = new DaoModule();

	public Case evaluateCode(Case targetCase, Case selectedCase) {
		return evaluateCode(targetCase, selectedCase.getScmUrl(), selectedCase.getProjectId());
	}

	public Case evaluateCode(Case targetCase, String scmUrl, Integer projectId) {
		logger.info("FeedbackModule.evaluateCode");
		targetCase.setScmUrl(scmUrl);
		targetCase.setProjectId(projectId);
		targetCase.setDimension("methodName", new Dimension(StringHelper.joinAndUpperCase(targetCase)));

		try {
			daoModule.insertCase(targetCase);
			return targetCase;
		} catch (Exception e) {
			logger.error("FeedbackModule.evaluateCode ERROR: ", e);
			return null;
		}
	}
}
